﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace Faust.Andrew.MTG.Player.Shared
{
    /// <summary>
    /// Represents a player in the game
    /// </summary>
    [DataContract]
    public class Player : INotifyPropertyChanged
    {
        public Player()
        {
            Name = String.Empty;
            DeckName = String.Empty;
            Counters = new ObservableCollection<Counter>();
            LifeCounter = 20;
            Order = 0;
        }
        protected int _playerID;
        /// <summary>
        /// Unique id for the player. Used to represent the player when actions are taken
        /// </summary>
        [DataMember]
        public int PlayerID
        {
            get
            {
                return _playerID;
            }
            set
            {
                if (_playerID != value)
                {
                    _playerID = value;
                    FirePropertyChanged("PlayerID");
                }
            }
        }

        protected string _name;
        [DataMember]
        public string Name
        {
            get
            {
                return _name;
            }
            set
            {
                if (_name != value)
                {
                    _name = value;
                    FirePropertyChanged("Name");
                }
            }
        }

        protected string _deckName;
        [DataMember]
        public string DeckName
        {
            get
            {
                return _deckName;
            }
            set
            {
                if (_deckName != value)
                {
                    _deckName = value;
                    FirePropertyChanged("DeckName");
                }
            }
        }

        protected int _deckCount;
        [DataMember]
        public virtual int DeckCount
        {
            get
            {
                return _deckCount;
            }
            set
            {
                if (_deckCount != value)
                {
                    _deckCount = value;
                    FirePropertyChanged("DeckCount");
                }
            }
        }

        protected int _handCount;
        [DataMember]
        public virtual int HandCount
        {
            get
            {
                return _handCount;
            }
            set
            {
                if (_handCount != value)
                {
                    _handCount = value;
                    FirePropertyChanged("HandCount");
                }
            }
        }

        protected int _graveyardCount;
        [DataMember]
        public virtual int GraveyardCount
        {
            get { return _graveyardCount; }
            set
            {
                if (_graveyardCount != value)
                {
                    _graveyardCount = value;
                    FirePropertyChanged("GraveyardCount");
                }
            }
        }

        protected ObservableCollection<Counter> _counters;
        /// <summary>
        /// Any counters that may be on the player (such as poison counters)
        /// </summary>
        [DataMember]
        public ObservableCollection<Counter> Counters
        {
            get
            {
                return _counters;
            }
            set
            {
                if (_counters != value)
                {
                    _counters = value;
                    FirePropertyChanged("Counters");
                }
            }
        }

        protected int _lifeCounter;
        /// <summary>
        /// The targetPlayerID's Current Life
        /// </summary>
        [DataMember]
        public int LifeCounter
        {
            get
            {
                return _lifeCounter;
            }
            set
            {
                if (_lifeCounter != value)
                {
                    _lifeCounter = value;
                    FirePropertyChanged("LifeCounter");
                }
            }
        }

        protected int _order;
        /// <summary>
        /// Position of the player in the turn order. Position 0 being the first to act.
        /// </summary>
        [DataMember]
        public int Order
        {
            get
            {
                return _order;
            }
            set
            {
                if (_order != value)
                {
                    _order = value;
                    FirePropertyChanged("Order");
                }
            }
        }

        private bool _isDeckUnlocked;
        [DataMember]
        public bool IsDeckUnlocked
        {
            get
            {
                return _isDeckUnlocked;
            }
            set
            {
                if (_isDeckUnlocked != value)
                {
                    _isDeckUnlocked = value;
                    FirePropertyChanged("IsDeckUnlocked");
                }
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        protected void FirePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion
    }
}
